package top.mengchaob.deploy;

import top.mengchaob.deploy.table.HostServerDO;
import top.mengchaob.deploy.util.CloseChannel;
import top.mengchaob.deploy.util.SSHUtil;
import top.mengchaob.deploy.util.SftpProgressMonitorImpl;
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.SftpException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

/**
 * @title：
 * @author: mengchaob
 * @date: 2021年04月27日 11:26
 * @description:
 */
public class Deploy {
    private static Logger logger = LoggerFactory.getLogger(Deploy.class);
    public static void main(String[] args) {
        /**
         * 初始化连接
         */
//        HostServerDO sshLoginInfo = new HostServerDO();
//        sshLoginInfo.setHost("10.10.66.126");
//        sshLoginInfo.setUserName("root");
//        sshLoginInfo.setTimeOut(30000);
//        sshLoginInfo.setPort(22);
//        sshLoginInfo.setPassWord("Yonyou@1988*126");
//        ChannelSftp channelSftp = null;
//        try {
//            SftpProgressMonitorImpl sftpProgressMonitorImpl = new SftpProgressMonitorImpl();
//            channelSftp = SSHUtil.getChannelSftp(sshLoginInfo);
//            File file = new File("D://SSOURL.jar");
//            InputStream is = new FileInputStream(file);
//            channelSftp.connect();
//            logger.debug("目录："+channelSftp.ls("/home/"));
//            /**
//             * 覆盖模式
//             */
//            channelSftp.put(is,"/home/aa.jar",sftpProgressMonitorImpl,ChannelSftp.OVERWRITE);
//            try {
//                is.close();
//            }catch (Exception e){
//                e.printStackTrace();
//            }
//            CloseChannel.close(channelSftp);
//            channelSftp.exit();
//            logger.debug("退出上传！");
//
//        } catch (JSchException | SftpException | FileNotFoundException e) {
//            e.printStackTrace();
//            CloseChannel.close(channelSftp);
//        }

    }
}
